package ir;

import ic.ast.decl.DeclClass;
import ic.ast.decl.DeclMethod;
import java.util.Map;

import scoping.ScopeTree;
import scoping.blocks.ClassScope;

public class DVInstruction {
	private DeclClass declClass;
	
	public DVInstruction(DeclClass declClass) {
		this.declClass = declClass;
	}
	
	@Override
	public String toString(){
		return getDispatchVectors(declClass);
	}
	
	private String getDispatchVectors(DeclClass declClass){
		StringBuilder sb = new StringBuilder();
		ClassScope classScope = (ClassScope)declClass.getScope().getBlock();
		sb.append(String.format(":%s\n", 
				LabelGenerator.generateClassDVLabel(declClass.getName())));
		
		for (Map.Entry<DeclMethod, DeclClass> entry:classScope.getMethodsAndClasses().entrySet()){
			String methodLabel = LabelGenerator.generateMethodName(entry.getValue().getName(), entry.getKey().getName());
			sb.append(String.format("\t(:%s)\n", methodLabel));
		}
		
		return sb.toString();
	}
}
